<?php
namespace app\adminplatform\controller;

use app\adminplatform\model\AuthGroup;
use app\adminplatform\model\City;
use app\adminplatform\model\BackMenu;
use think\facade\App;
use think\facade\Config;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;

class Index extends Initial {
    /**
     * 后台首页
     */
    public function index(){
        //左侧菜单列表
        if(Request::isPost()) {
            $list = BackMenu::getBackMenuList()->toArray(); //获取菜单列表数组
            $menu = BackMenu::getBackMenuChild($list);      //将菜单按子父嵌套排列
            //管理员是否有菜单显示权限
            return json(["info"=>AuthGroup::menuAuthCheck(Session::get('userData'), $menu), "status"=>1]);
        }
        //管理员信息
        View::assign('userData', Session::get('userData'));
        return View::fetch('index');
    }
    /**
     * 欢迎页
     */
    public function welcome(){
		$info = array(
            '操作系统' => PHP_OS,
            '运行环境' => $_SERVER["SERVER_SOFTWARE"],
            '主机名' => $_SERVER['SERVER_NAME'],
            'WEB服务端口' => $_SERVER['SERVER_PORT'],
            '网站文档目录' => $_SERVER["DOCUMENT_ROOT"],
            '浏览器信息' => substr($_SERVER['HTTP_USER_AGENT'], 0, 40),
            '通信协议' => $_SERVER['SERVER_PROTOCOL'],
            '请求方法' => $_SERVER['REQUEST_METHOD'],
            'ThinkPHP版本' => App::version(),
            '上传附件限制' => ini_get('upload_max_filesize'),
            '执行时间限制' => ini_get('max_execution_time').'秒',
            '服务器时间' => date("Y年m月d日 H:i:s"),
            '北京时间' => gmdate("Y年m月d日 H:i:s",time()+8*3600),
            '服务器域名/IP' => $_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            '用户的IP地址' => $_SERVER['REMOTE_ADDR'],
            '剩余空间' => round((disk_free_space(".")/(1024*1024)),2).'M',
        );
		View::assign('info',$info);
        View::assign('support', Config::get("app.support"));
        return View::fetch('welcome');
    }
    /**
     * 加载所选省份下的城市or区县
     */
    public function getCityList(){
        $parentId = intval(Request::post('parentId'));
        //查询所选城市下级id
        $info = City::getUnderCity($parentId);
        $data['info'] = $info;
        $data['status'] = 1;
        return json($data);
    }
    /**
     * tinymce图片上传接口
     */
    public function tinymceImgUpload(){
        $website = website();
        $info = uploadFile("file", Config::get("app.tinymce_url"), $website["sy_photoMaxSize"]);
        if(!empty($info['src'])) {
            $src = Config::get("app.view_string.__upload__")."/".$info['src'];
            $info = ["code"=> 0, "msg"=>"上传成功", "data" => $src]; //改为layui tinymce 识别格式
        }
        return json($info);
    }
}
